package com.xxx.blog.base.service.impl;

import com.xxx.blog.base.dao.SysUserMapper;
import com.xxx.blog.base.domain.SysUser;
import com.xxx.blog.base.service.UserService;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.shiro.crypto.hash.Sha256Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/*******************************************************************************
 * Project: blog-base
 * Package: com.xxx.blog.base.service.impl
 * Type:    UserServiceImpl
 * Author:  ChenXuefei
 * Date:    2017/12/12 16:08
 *
 * Copyright (c) 2017 AFCATSTAR. All Rights Reserved.
 *******************************************************************************/
@Service("userService")
public class UserServiceImpl implements UserService {
    @Autowired
    private SysUserMapper sysUserMapper;
    
    @Override
    public void addUser(SysUser sysUser) {
        sysUser.setUsername("超级管理员");
        String random = RandomStringUtils.randomAlphanumeric(20);
        String passW = new Sha256Hash("123456", random).toHex();
        sysUser.setPassword(passW);
        sysUser.setSalt(random);
        sysUser.setStatus(Byte.valueOf("1"));
        sysUser.setCreateTime(new Date());
        sysUserMapper.insert(sysUser);
    }
    
    public static void main(String[] args){
        String random = RandomStringUtils.randomAlphanumeric(20);
        System.out.println(random);
        String passW = new Sha256Hash("123456", random).toHex();
        System.out.println(passW);
    }
}
